home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swaga_c.zip / ANSI.SWG / 0003_ANSI Display Unit.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  68 lines

  1. {
  2. >How do I make an ansi and put it in my Pascal File?  I know there is an
  3. >option to save as pascal, but it does not look like anything to me!
  4. >Any help is appreciated!
  5.  
  6. Here is a Program that will read an ANSI File into a buffer in 2k chunks
  7. then Write it (to screen) Character by Character. BUT - it will Write
  8. all ANSI-escape-sequences as StringS.
  9.  
  10.    Two reasons For this:
  11.  
  12.  1) I just 'feel happier' if each ANSI escape sequence is written to
  13.  screen as a String instead of as individual Characters. (Its just an
  14.  irrational 'thing' I have)
  15.  
  16.  2) By assembling all the Characters in the escape sequence together,
  17.  it make its _easy_ to FILTER OUT all ANSI sequences if you want to just
  18.  output plain black-and-white Text. This is For those people who for
  19.  some strange reason would rather not have ANSI.SYS installed, but
  20.  complain about getting 'garbage' Characters on the screen.
  21.  
  22. All you have to do to filter out the escape sequences is to
  23. un-bracket the 'if AnsiDetected then' part.
  24.  
  25. if you want me to post 'Function AnsiDetected: Boolean' just let me
  26. know.
  27. }
  28.  
  29. Program ansiWrite;
  30.  
  31. Const esc = chr(27);
  32.       termnChar: SET of Char =
  33.                  ['f','A'..'D','H','s','u','J','K','l'..'n','h'];
  34.  
  35. Var f: File;
  36.     buf:Array[1..2048] of Char;
  37.     Numread: Word;
  38.     num: Integer;
  39.     escString: String;
  40.     escseq: Boolean;
  41.  
  42. begin
  43.   Assign(f,'FRINGE3.ANS');
  44.   Reset(f,1);
  45.   escseq := False;
  46.   escString:='';
  47.   Repeat
  48.     BlockRead(f,buf,Sizeof(Buf),Numread);
  49.     { Write Block to Screen }
  50.     For NUM := 1 to Numread DO
  51.     begin
  52.       if Buf[Num] = esc then escseq := True;
  53.       if escseq=True then
  54.       begin
  55.         escString:= escString+buf[num];
  56.         if Buf[num] in termnChar  then
  57.         begin
  58.           escseq:=False;
  59.           {if AnsiDetected then} Write(escString);
  60.           escString:=''
  61.         end
  62.       end
  63.       else Write(Buf[num])
  64.     end; { For }
  65.   Until NumRead < SizeOf(Buf);
  66.   close(f)
  67. end.
  68.